#
# This file is part of uscp, an open-source cross-platform package tool
# 2008  Rafael Sachetto
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Contact e-mail: Rafael Sachetto <rsachetto@gmail.com>
# Program URL   : http://code.google.com/p/uspc/

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QTreeWidget, QAbstractItemView

class myQTreeWidget(QTreeWidget):

    def __init__(self,parent=None):

        QTreeWidget.__init__(self,parent)

        itemList = []
        self.setRootIsDecorated(False);
        self.setAlternatingRowColors(True);

        itemList.append("Package");
        itemList.append("Size (Kb)");
        itemList.append("Release");
        itemList.append("Architecture");
        itemList.append("Status");
        itemList.append("URL");

        self.setSelectionMode(QAbstractItemView.ExtendedSelection);
        self.sortItems(0, Qt.AscendingOrder);
        self.setHeaderLabels(itemList);
        self.setUniformRowHeights(True);
        self.setSortingEnabled(True);
        self.setAcceptDrops(True);
        self.setContextMenuPolicy(Qt.CustomContextMenu)

    def keyPressEvent(self, k):
        """
        Handle the key pressed events.
        Remove the item when the delete key is pressed.
        """

        if k.key() == Qt.Key_Delete:
            for i in range(self.topLevelItemCount()):
                if self.topLevelItem(i).isSelected():
                    self.takeTopLevelItem(i);
